


"""
1，说明r，w与a三者间的区别。
2，读取iris.txt文件数据，并存入列表中：
"""

class Practice0808:
    def __init__(self  , *args):
        self.filePath = args[0]
        self.readFileName = args[1]
        self.writerFileName = args[2]
        self.appendFileName2 = args[3]

    def get_file_data(self):
        result = []
        fileName = self.filePath+self.readFileName
        with open(file=fileName , mode = 'r' , encoding='utf8') as file:
            result = file.read()
        print(f"{fileName}文件内容:\r\n{result}")
        return result

    def writer_file_data(self):
        result = ['你好1' , 'wo时1' ,'zhang san1']
        fileName = self.filePath+self.writerFileName
        with open(file=fileName , mode = 'w' , encoding='utf8') as file:
            result = file.write(",".join(result))
        print(f"{fileName}覆盖写入完成")
        return result


    def append_file_data(self):
        result = ['你好' , 'wo时' ,'zhang san']
        fileName = self.filePath+self.appendFileName2
        with open(file=fileName , mode = 'a' , encoding='utf8') as file:
            result = file.write(",".join(result)+"\n")
        print(f"{fileName}追加写入完成")
        return result


#mode ：可选参数，文件打开的模式
# r：默认以读的模式打开的，如果文件不存在会报错
# w：以覆盖写的模式打开，如果不存在会创建文件
# a：以追加写的文件打开，如果不存在会创建文件


obj = Practice0808('' , 'iris.txt' , 'file_1.txt' , 'file_2.txt')
obj.get_file_data()
obj.writer_file_data()
obj.append_file_data()